package br.com.bringme.mvc;

import java.util.HashMap;

public final class Singleton {

	private static HashMap<Class<?>, Object> instances = new HashMap<Class<?>, Object>();
	
	@SuppressWarnings("unchecked")
	public static <T> T getInstance(Class<T> clazz) {
		
		T instance = (T) instances.get(clazz);
		try {
			
			if(instance == null) {
				instance = clazz.newInstance();
				instances.put(clazz, instance);
			}
			
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		
		return instance;
	}
	
}
